package cn.finyzq.ss.games.web.ctrl;

import cn.finyzq.ss.games.service.RoomService;
import cn.finyzq.ss.games.utils.SessionUtils;
import cn.finyzq.ss.games.vo.ResultBean;
import cn.finyzq.ss.games.vo.Room;
import cn.finyzq.ss.games.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Optional;

/**
 * Create Time: 2018年08月05日 12:39
 *
 * @author fin
 */
@RestController
@RequestMapping("/api/v1/rooms")
public class RoomCtrl extends BaseCtrl {

    @Autowired
    private RoomService roomService;

    @PostMapping("/openRoom")
    public ResultBean openRoom(HttpServletRequest request, Optional<Integer> gameType, Optional<Boolean> force) {
        User user = SessionUtils.getUser(request);
        return roomService.openRoom(user, gameType.orElse(Room.PAINT), force.orElse(false));
    }

    @GetMapping("")
    public ResultBean getRoom(HttpServletRequest request) {
        User user = SessionUtils.getUser(request);
        return roomService.findUserRoom(user);
    }

    @GetMapping("/{roomNo}")
    public ResultBean<Room> roomDetail(@PathVariable String roomNo) {
        return roomService.findRoom(roomNo);
    }




}
